/*
============================================================================
 Name        : dd_task_worker.h
 Author      : Jian
 Version     :
 Copyright   : GPL
 Description : dd_task_worker.h - header file
============================================================================
*/

#ifndef DD_TASK_WORKER_H
#define DD_TASK_WORKER_H

/* INCLUDES */
#include "dd_define.h"

__DD_BEGIN_DECLS

#define DD_INVALID_TASK_ID  ((DD_UINT)-1)


struct __dd_vector ;
typedef struct __dd_task dd_task ;
typedef struct __dd_task_worker dd_task_worker ;

struct __dd_task {
    int  id ;  /* CAN'T CHANGED */
    int  (*priority)(dd_task* task) ;
    void (*work)(dd_task* task) ;
    void (*destroy)(dd_task* task) ;
};

struct __dd_task_worker {

    struct __dd_vector* taskList ;
    struct __dd_vector* threadList ;
    struct __dd_task**  curTasks ;
    sd_rlock*           listLock ;
    sd_semp*            waitSem ;
    sd_semp*            cancelSem ;
    int                 isEnablePriority ;
    DD_UINT             incTaskId ;
};


dd_task_worker* dd_worker_create(DD_UINT startTaskId, int threadCount, int isEnablePriority) ;

void dd_worker_destroy(dd_task_worker* worker) ;

/* return DD_INVALID_TASK_ID ((DD_UINT)-1), mean got some error */
DD_UINT dd_worker_add(dd_task_worker* worker, dd_task* task) ;

int dd_worker_update(dd_task_worker* worker, DD_UINT taskId, void taskUpdate(dd_task*)) ;

__DD_END_DECLS	

#endif  /* DD_TASK_WORKER_H */

/* End of File */
